﻿@page "/counter"
@using Microsoft.AspNetCore.Authorization

@inject IHttpClientFactory Factory
@attribute [Authorize]

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private async void IncrementCount()
    {
        try
        {
            var httpClient = Factory.CreateClient("stickerwall");
            var request = new HttpRequestMessage(HttpMethod.Get, "api/stickers");
            //request.SetBrowserRequestCredentials(BrowserRequestCredentials.Omit);
            var result = await httpClient.SendAsync(request);
            var sc = result.StatusCode;
            Console.WriteLine(sc);
            result.EnsureSuccessStatusCode();
            currentCount++;
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
        
    }
}
